package org.tangzsoft.pdmviewer.utils.config;

import java.util.Locale;
import java.util.ResourceBundle;

public class ResourceBundlePropertySet extends AbstractPropertySet {

	private ResourceBundle _bundle;
	
	public ResourceBundlePropertySet(ResourceBundle bundle) {
		_bundle = bundle;
	}
    
    public ResourceBundlePropertySet(String path) {
        
        Locale currentLocale = Locale.getDefault();
		
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
		if (cl == null) {
		    cl = ClassLoader.getSystemClassLoader();
		}
        
        _bundle = ResourceBundle.getBundle(path, currentLocale, cl);
        
    }
	
    @Override
	protected String getProperty(String name) throws Exception {
        if (!_bundle.containsKey(name)) {
            throw new Exception("property("+name+") no exists!");
        }
		return _bundle.getString(name);
	}

}
